package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.domain.PmsMemberPrice;
import com.itheima.mapper.PmsMemberPriceMapper;
import com.itheima.service.db.PmsMemberPriceService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsMemberPriceServiceImpl implements PmsMemberPriceService {
    @Autowired
    PmsMemberPriceMapper pmsMemberPriceMapper;

    @Override
    public List<PmsMemberPrice> selectByProductId(Integer id) {
        LambdaQueryWrapper<PmsMemberPrice> lqw=new LambdaQueryWrapper<>();
        lqw.eq(PmsMemberPrice::getProductId,id);
        return pmsMemberPriceMapper.selectList(lqw);
    }
    @Override
    public void updateByProductId(Integer id, List<PmsMemberPrice> pmsMemberPriceList) {
        LambdaQueryWrapper<PmsMemberPrice> lqw=new LambdaQueryWrapper<>();
        lqw.eq(PmsMemberPrice::getProductId,id);
        pmsMemberPriceMapper.delete(lqw);

        for (PmsMemberPrice pmsMemberPrice : pmsMemberPriceList) {
            pmsMemberPrice.setProductId(id.longValue());
            pmsMemberPriceMapper.insert(pmsMemberPrice);
        }

    }

    @Override
    public void save(Long productId, List<PmsMemberPrice> memberPriceList) {
        for (PmsMemberPrice pmsMemberPrice : memberPriceList) {
            pmsMemberPrice.setProductId(productId);
            pmsMemberPriceMapper.insert(pmsMemberPrice);
        }
    }
}
